cd "C:\Users\John\Dropbox\Research\Gun Control\TAPS"

clear all 
set maxvar 30000
use "TAPS 2016.dta"
merge 1:1 wustlid using "TAPS 2014.dta"
drop _merge
merge 1:1 wustlid using "TAPS PROFILE.dta"

gen guns1=GUNS14S51
gen guns2=GUNS15S51
gen guns3=GUNS12S51
gen guns4=GUNS11S51
gen guns5=GUNS13S51
recode guns1 1=. 2=1 3=0 4=.
recode guns2 1=. 2=1 3=0 4=.
recode guns3 1=. 2=1 3=0 4=.
recode guns4 1=. 2=1 3=0 4=.
recode guns5 1=. 2=1 3=0 4=.

*TRUST
gen trust1=TRUSTGOVS34
recode trust1 1=. 2=3 3=2 4=1

**OTHER VARIABLES
**Obama Approval
gen prezapprove=APPRPRESS51
recode prezapprove 1=. 2=1 3=.6667 4=.3333 5=0 6=.
gen congapprove=APPRCONGS51
recode congapprove 1=. 2=1 3=.6667 4=.3333 5=0 6=.

**IDEOLOGY
gen ideology=LIBCON0S57
recode ideology 1=. 2=1 3=2 4=3 5=4 6=5 7=.
*greater values conservative

*PARTY ID
**greater values republican
gen pid7=.
replace pid7=1 if PARTYID1S54==2 & PARTYID2S54==2
replace pid7=2 if PARTYID1S54==2 & PARTYID2S54==3
replace pid7=6 if PARTYID1S54==3 & PARTYID2S54==3
replace pid7=7 if PARTYID1S54==3 & PARTYID2S54==2
replace pid7=4 if PARTYID3S54==1 & PARTYID1S54==4
replace pid7=3 if PARTYID3S54==2 & PARTYID1S54==4
replace pid7=5 if PARTYID3S54==3 & PARTYID1S54==4
replace pid7=4 if PARTYID4S54==1 & PARTYID1S54==5
replace pid7=3 if PARTYID4S54==2 & PARTYID1S54==5
replace pid7=5 if PARTYID4S54==3 & PARTYID1S54==5

gen repstr=pid7
recode repstr 1=0 2=0 3=0 4=0 5=1 6=2 7=3
gen demstr=pid7
recode demstr 1=3 2=2 3=1 4=0 5=0 6=0 7=0

gen pid3=pid7
recode pid3 1=1 2=1 3=1 4=2 5=3 6=3 7=3

gen dem=pid3
recode dem 1=1 2=0 3=0

gen rep=pid3
recode rep 1=0 2=0 3=1


**AGE
gen age=agesp+2
recode age 80/120=80

**EDUCATION
gen education=educsp
recode education -1=. 2=1 3=1 4=1 5=1 6=1 7=1 8=1 9=2 10=2 11=2 12=3 13=4 14=4 15=4

gen highschool=education
recode highschool 1=0 2=1 3=0 4=0
gen college=education
recode college 1=0 2=0 3=1 4=0
gen graduate=education
recode graduate 1=0 2=0 3=0 4=1

**RACE/GENDER
gen female=gendersp
recode female -1=. 1=0 2=1

gen hispanic=HISPAN1SP
recode hispanic -1=. 1=1 2=0

gen white=RACE1SP
gen black=RACE2SP

*INCOME
gen income=income6
*Gun Owner
gen gunowner=GUNS3S51
recode gunowner 1=. 2=1 3=0 4=.

keep wustlid guns1 guns2 guns3 guns4 guns5 demstr repstr dem rep trust1 gunowner ideology age pid7 pid3 highschool college graduate female hispanic white black income prezapprove congapprove

save "TAPS Recoded.dta", replace
gen qversion=1
append using "TAPS Recoded.dta"
replace qversion=2 if qversion==.
append using "TAPS Recoded.dta"
replace qversion=3 if qversion==.
append using "TAPS Recoded.dta"
replace qversion=4 if qversion==.
append using "TAPS Recoded.dta"
replace qversion=5 if qversion==.

gen gunq=guns1 if qversion==1
replace gunq=guns2 if qversion==2
replace gunq=guns3 if qversion==4
replace gunq=guns4 if qversion==3
replace gunq=guns5 if qversion==5

replace trust1=(trust1-1)/2
replace qversion=(qversion-1)/4
replace ideology=(ideology-1)/4
replace pid7=(pid7-1)/6
replace age=(age-20)/60
replace income=(income-1)/5

logit gunq c.trust1 c.ideology c.qversion pid7 i.gunowner congapprove prezapprove highschool college graduate female age black hispanic white income, cluster(wustlid)
estat ic
logit gunq c.trust1##c.ideology##c.qversion pid7 i.gunowner congapprove prezapprove highschool college graduate female age black hispanic white income, cluster(wustlid)
estat ic

cls

margins, at(trust1=0 qversion=(0(.25)1) ideology=0)
margins, at(trust1=1 qversion=(0(.25)1) ideology=0)
margins, at(trust1=0 qversion=(0(.25)1) ideology=0.5)
margins, at(trust1=1 qversion=(0(.25)1) ideology=0.5)
margins, at(trust1=0 qversion=(0(.25)1) ideology=1)
margins, at(trust1=1 qversion=(0(.25)1) ideology=1)

margins, dydx(trust1) at(qversion=(0(.25)1) ideology=0)
margins, dydx(trust1) at(qversion=(0(.25)1) ideology=.5)
margins, dydx(trust1) at(qversion=(0(.25)1) ideology=1)
